package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author 老李头儿
 * @since 2025-03-27
 */
@RestController
@RequestMapping("/questions")
@Api(tags = "用户端-问题相关接口")
@RequiredArgsConstructor
public class InteractionQuestionController {
    private final IInteractionQuestionService questionService;

    /**
     * 新增提问
     *
     * @param questionDTO
     */
    @ApiOperation("新增提问")
    @PostMapping
    public void saveQuestion(@RequestBody QuestionFormDTO questionDTO) {
        questionService.saveQuestion(questionDTO);
    }

    /**
     * 修改问题
     *
     * @param id
     */
    @ApiOperation("修改问题")
    @PutMapping("/{id}")
    public void updateQuestion(@PathVariable Long id ,@RequestBody @ApiParam("要修改的问题信息") QuestionFormDTO questionDTO) {
        questionService.updateQuestion(id,questionDTO);
    }

    /**
     * 分液查询问题
     */
    @ApiOperation("分页查询问题")
    @GetMapping("/page")
    public PageDTO<QuestionVO> pageQuestions(QuestionPageQuery query) {
        return questionService.pageQuestions(query);
    }

    /**
     * 根据id查询问题详情
     * @param id
     * @return
     */
    @ApiOperation("根据id查询问题详情")
    @GetMapping("/{id}")
    public QuestionVO queryQuestionById(@ApiParam(value = "问题id", example = "1") @PathVariable("id") Long id){
        return questionService.queryQuestionById(id);
    }

    /**
     * 根据id删除当前用户问题
     * @param id
     */
    @ApiOperation("根据id删除当前用户问题")
    @DeleteMapping("/{id}")
    public void deleteQuestion(
            @ApiParam(value = "问题id", example = "1") @PathVariable("id") Long id
    ){
        questionService.deleteById(id);
    }

}
